スキップしてメイン コンテンツに移動

Understanding Logistic Regression from Scratch

 Logistic regression is one of the most popular methods at the intersection of statistics and machine learning.


Despite its name including “regression”, it’s actually a classification model that predicts “0 or 1”. 


With its intuitive probabilistic interpretation and simple implementation, it's widely used in a variety of fields, from business to healthcare and web analytics.



1. What is Logistic Regression?



While general linear regression predicts continuous values, logistic regression outputs the probability of an event occurring.


By classifying instances as class 1 if the resulting probability exceeds a threshold, and class 0 if it falls below, it solves binary classification problems.


Estimation is performed by maximising the log-likelihood function to best explain the correct labels.


Mathematically, it involves finding the gradient and iteratively updating, meaning you can complete learning with just a few lines of code using Python’s `scikit-learn` or `statsmodels`.



2. Where is it Used?



Due to its high interpretability and low implementation cost, logistic regression is often the first choice in many industries and applications.


- Medical Diagnosis: Predicting whether a patient has a disease based on test results and medical history.

- Credit Scoring: Determining creditworthiness based on an applicant’s attributes and credit history.

- Customer Churn Prediction: Estimating the risk of cancellation based on purchase history and usage frequency.

- Marketing: Binary classification of email open rates and advertising click-through rates.

- HR & Recruitment: Evaluating candidate suitability and the risk of early departure based on applicant information.

- Anomaly Detection in Manufacturing: Determining the presence of equipment failure based on sensor data.


By looking at the weights and odds ratios, you can intuitively understand how much each explanatory variable influences the result.



3. Benefits of Learning It?



- It’s easy to explain the impact of variables on the result to business stakeholders using odds ratios and the signs of coefficients.

- It’s a good first step to learning evaluation metrics (ROC curve, AUC, Precision-Recall).

- Compared to decision trees or SVMs, it can provide numerical justification for “why” a prediction was made.

- It provides a foundation for developing to multi-class classification (Softmax regression).

- It can serve as foundational knowledge for hierarchical Bayesian models and generalised linear models.

- You can incorporate probabilistic predictions directly into subsequent decision-making, such as credit ratings and patient risk scoring.

- Understanding maximum likelihood estimation, gradient methods, and regularisation can be applied to deep learning.

- Overfitting can be suppressed by combining regularisation and variable selection.

- It can be implemented with just a few lines of code using standard Python/R libraries, and can handle large datasets using mini-batch learning.



Summary



Logistic regression is not only directly applicable to your work but also an essential stepping stone to more advanced algorithms. 


Let’s start by implementing logistic regression with your own hands and experiencing the fun of probabilistic prediction.

If you want to learn logistic regression, we recommend this book (access here).


コメント

このブログの人気の投稿

Understanding the Modified Euler Method (Heun's Method) from Scratch

This article explains the basic concepts, applications, and benefits of learning the Modified Euler Method (Heun's Method). This method, a step forward from the simple Euler method, plays a very important role in the world of numerical analysis. 1. What is the Modified Euler Method (Heun's Method)? The Modified Euler Method, also known as Heun’s Method, is a numerical method for obtaining approximate solutions to initial value problems: dy/dt = f(t, y), y(t_0) = y_0 The traditional Euler method determines the next value, y_{n+1}, using only the slope of the tangent line at time t_n, namely f(t_n, y_n).  However, when the step size is large or the problem exhibits strong non-linearity, this can lead to significant errors. A key feature of Heun’s Method is its ability to achieve higher accuracy (local error of second order) through a two-stage evaluation process, improving upon the Euler method. 2. In What Scenarios is it Applied? Due to its simplicity and improved accuracy, Heun...

Lista de publicaciones del Dr. Mint (en inglés)

   Mint Publishing ha publicado los siguientes libros. Todos ellos son fáciles de entender y están cuidadosamente explicados para que puedas comprenderlos desde cero. Las siguientes series ya están disponibles.   Serie Inteligencia Artificial   Serie Matemáticas   Serie Física   Serie Procesamiento de Imágenes   Serie Cálculo y Análisis Numérico   Serie Python   Serie R Las series están organizadas de tal manera que puedes aprender de la que más te interese, o puedes empezar con el primer volumen de la serie en orden. Al ir y venir entre las series, el contenido es altamente sinérgico entre sí. A continuación se enumeran los libros. (Para más información sobre cada libro, visite la página del libro correspondiente).   Serie Inteligencia Artificial   [1]. Entendiendo los perceptrones : Una base para el aprendizaje profundo  (próximamente) [2]. Understanding the Improved Perceptron (El...

Understanding Reciprocal Functions from Scratch

The reciprocal function is one of the fundamental functions in mathematics, and despite its simplicity, it’s a powerful tool with applications in many fields thanks to its unique characteristics. This article will provide a detailed explanation of the definition and properties of reciprocal functions, explore the contexts in which they are used, and outline the benefits of learning about them. 1. What is a Reciprocal Function? A reciprocal function returns the reciprocal of a given real number.  - Graph Shape The graph of a reciprocal function forms a hyperbola, with values increasing or decreasing rapidly as it approaches the origin. It takes the shape of a hyperbola spanning the first and third quadrants, and has asymptotes at x = 0 and y = 0. Behind this simple equation lies the concept of a multiplicative inverse, which forms the foundation of basic algebra. 2. Where are Reciprocal Functions Used? Due to their fundamental nature and simplicity, reciprocal functions are used in ...